package rickyGame.game.action
{
	import ricky.utils.FrameManager;
	import ricky.game.Actor;
	import ricky.game.action.Act2D;
	import ricky.utils.TimeServer;
	
	/**
	 * 按时间播放的动画
	 */
	public class TimeAnimAct extends Act2D
	{
		/**
		 * actor:Pu 目标</br>
		 * animProperty:String 目标播放的动画</br>
		 * endTime:Number 结束时间毫秒数</br>
		 */
		public function TimeAnimAct(actor:Actor, animProperty:String, endTime:Number)
		{
			super(actor);
			this._animProperty=animProperty;
			_endTime=endTime;
			_type="TimeAnimAct";
		}
		
		override public function begin():void
		{
			super.begin();
			_startTime=TimeServer.now();
			FrameManager.inst.addLogic(getActor())
		}
		
		override public function action(timeline:Number):void
		{
			if(_state<1) //如果没有初始化
				return;
			if(timeline>=_endTime)
			{
				this.complete();
			}
		}
		
		override public function end():void
		{
			FrameManager.inst.removeLogic(getActor());
			super.end();
		}
		
		override public function dispose():void
		{
			_startTime=0;
			_endTime=0;
			super.dispose();
		}
		
		//******************* private **********************
		private var _startTime:Number;//开始时间毫秒数
		private var _endTime:Number;//持续时间毫秒数
	}
}